System.register(["@angular/platform-browser-dynamic", "@angular/platform-browser", "@angular/http", "ng2-layer", "@angular/core", "@angular/forms", "app/MenuComp", "app/ContentComp", "app/Directives", "app/AppComp", "app/LoginComp", "app/AppRoute", "app/Service", "app/Router/DataComp", "app/Router/OrderComp", "app/Router/pay/PayComp", "app/Router/pay/BindWxComp", "app/Router/UserComp", "app/Router/SettingComp", "app/Router/BoxComp", "app/Router/IndexSettingComp", "app/Router/boxSetting/BoxAccountComp", "app/Router/boxSetting/BoxAddressComp", "app/Router/boxSetting/BoxBaseComp", "app/Router/boxSetting/BoxNoticeComp", "app/Router/boxSetting/BoxShipComp", "app/Router/boxSetting/BoxTimeComp", "app/Router/boxSetting/BoxSettingIndexComp", "app/Router/boxProduct/BoxCategoryComp", "app/Router/boxProduct/BoxProductComp", "app/Router/boxProduct/BoxProductIndexComp"], function (exports_1, context_1) {
    "use strict";
    var __extends = (this && this.__extends) || function (d, b) {
        for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
    var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    };
    var __metadata = (this && this.__metadata) || function (k, v) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
    };
    var __moduleName = context_1 && context_1.id;
    var platform_browser_dynamic_1, platform_browser_1, http_1, ng2_layer_1, core_1, forms_1, MenuComp_1, ContentComp_1, Directives_1, AppComp_1, LoginComp_1, AppRoute_1, Service_1, DataComp_1, OrderComp_1, PayComp_1, BindWxComp_1, UserComp_1, SettingComp_1, BoxComp_1, IndexSettingComp_1, BoxAccountComp_1, BoxAddressComp_1, BoxBaseComp_1, BoxNoticeComp_1, BoxShipComp_1, BoxTimeComp_1, BoxSettingIndexComp_1, BoxCategoryComp_1, BoxProductComp_1, BoxProductIndexComp_1, Ajax, AppModule, _a, _b;
    return {
        setters: [
            function (platform_browser_dynamic_1_1) {
                platform_browser_dynamic_1 = platform_browser_dynamic_1_1;
            },
            function (platform_browser_1_1) {
                platform_browser_1 = platform_browser_1_1;
            },
            function (http_1_1) {
                http_1 = http_1_1;
            },
            function (ng2_layer_1_1) {
                ng2_layer_1 = ng2_layer_1_1;
            },
            function (core_1_1) {
                core_1 = core_1_1;
            },
            function (forms_1_1) {
                forms_1 = forms_1_1;
            },
            function (MenuComp_1_1) {
                MenuComp_1 = MenuComp_1_1;
            },
            function (ContentComp_1_1) {
                ContentComp_1 = ContentComp_1_1;
            },
            function (Directives_1_1) {
                Directives_1 = Directives_1_1;
            },
            function (AppComp_1_1) {
                AppComp_1 = AppComp_1_1;
            },
            function (LoginComp_1_1) {
                LoginComp_1 = LoginComp_1_1;
            },
            function (AppRoute_1_1) {
                AppRoute_1 = AppRoute_1_1;
            },
            function (Service_1_1) {
                Service_1 = Service_1_1;
            },
            function (DataComp_1_1) {
                DataComp_1 = DataComp_1_1;
            },
            function (OrderComp_1_1) {
                OrderComp_1 = OrderComp_1_1;
            },
            function (PayComp_1_1) {
                PayComp_1 = PayComp_1_1;
            },
            function (BindWxComp_1_1) {
                BindWxComp_1 = BindWxComp_1_1;
            },
            function (UserComp_1_1) {
                UserComp_1 = UserComp_1_1;
            },
            function (SettingComp_1_1) {
                SettingComp_1 = SettingComp_1_1;
            },
            function (BoxComp_1_1) {
                BoxComp_1 = BoxComp_1_1;
            },
            function (IndexSettingComp_1_1) {
                IndexSettingComp_1 = IndexSettingComp_1_1;
            },
            function (BoxAccountComp_1_1) {
                BoxAccountComp_1 = BoxAccountComp_1_1;
            },
            function (BoxAddressComp_1_1) {
                BoxAddressComp_1 = BoxAddressComp_1_1;
            },
            function (BoxBaseComp_1_1) {
                BoxBaseComp_1 = BoxBaseComp_1_1;
            },
            function (BoxNoticeComp_1_1) {
                BoxNoticeComp_1 = BoxNoticeComp_1_1;
            },
            function (BoxShipComp_1_1) {
                BoxShipComp_1 = BoxShipComp_1_1;
            },
            function (BoxTimeComp_1_1) {
                BoxTimeComp_1 = BoxTimeComp_1_1;
            },
            function (BoxSettingIndexComp_1_1) {
                BoxSettingIndexComp_1 = BoxSettingIndexComp_1_1;
            },
            function (BoxCategoryComp_1_1) {
                BoxCategoryComp_1 = BoxCategoryComp_1_1;
            },
            function (BoxProductComp_1_1) {
                BoxProductComp_1 = BoxProductComp_1_1;
            },
            function (BoxProductIndexComp_1_1) {
                BoxProductIndexComp_1 = BoxProductIndexComp_1_1;
            }
        ],
        execute: function () {
            Ajax = (function (_super) {
                __extends(Ajax, _super);
                function Ajax(backend, layer, notify) {
                    var _this = _super.call(this, backend, new http_1.BaseRequestOptions()) || this;
                    _this.layer = layer;
                    _this.notify = notify;
                    _this.url = "http://api.txiaoyuan.cn/index/";
                    _this._defaultOptions.headers.append("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
                    return _this;
                }
                Ajax.prototype.request = function (url, options) {
                    return _super.prototype.request.call(this, url, options);
                };
                Ajax.prototype.get = function (options) {
                    var _this = this;
                    options.body = this._parseBody(options.body);
                    options.search = this._parseBody(options.search);
                    options.withCredentials = 'true';
                    var ly = null;
                    if (options.message) {
                        ly = this.layer.loading({ message: "loading...", isModal: true });
                    }
                    if (options.url) {
                        options.url = this.url + options.url;
                    }
                    else {
                        options.url = this.url + "t.php";
                    }
                    return new Promise(function (resolve, reject) {
                        _super.prototype.get.call(_this, options.url, options).subscribe(function (res) {
                            var data = res.json();
                            if (data.code == 200) {
                                resolve(data);
                            }
                            else {
                                if (data.code == 0) {
                                    _this.notify.emit(false);
                                }
                                _this.layer.tip({
                                    message: data.message,
                                    align: "top"
                                });
                            }
                            if (ly) {
                                ly.close();
                            }
                        });
                    });
                };
                Ajax.prototype.post = function (options) {
                    var _this = this;
                    options.body = this._parseBody(options.body);
                    options.search = this._parseBody(options.search);
                    options.withCredentials = 'true';
                    if (options.url) {
                        options.url = this.url + options.url;
                    }
                    else {
                        options.url = this.url + "t.php";
                    }
                    var ly = null;
                    if (options.message) {
                        ly = this.layer.loading({ message: "loading...", isModal: true });
                    }
                    return new Promise(function (resolve, reject) {
                        _super.prototype.post.call(_this, options.url, null, options).subscribe(function (res) {
                            var data = res.json();
                            if (data.code == 200) {
                                resolve(data);
                            }
                            else {
                                if (data.code == 0) {
                                    _this.notify.emit(false);
                                }
                                _this.layer.tip({
                                    message: data.message
                                });
                            }
                            if (ly) {
                                ly.close();
                            }
                        });
                    });
                };
                Ajax.prototype._parseBody = function (obj) {
                    if (!obj || String(obj) == '[object File]' || obj instanceof FormData || typeof obj == "string")
                        return obj;
                    var query = '', name, value, fullSubName, subName, subValue, innerObj, i;
                    for (name in obj) {
                        value = obj[name];
                        if (value instanceof Array) {
                            for (i = 0; i < value.length; ++i) {
                                subValue = value[i];
                                if (subValue == 0 || subValue) {
                                    fullSubName = name + "[]";
                                    innerObj = {};
                                    innerObj[fullSubName] = subValue;
                                    query += this._parseBody(innerObj) + '&';
                                }
                            }
                        }
                        else if (value instanceof Object) {
                            for (subName in value) {
                                subValue = value[subName];
                                if (subValue == 0 || subValue) {
                                    fullSubName = name + '.' + subName;
                                    innerObj = {};
                                    innerObj[fullSubName] = subValue;
                                    query += this._parseBody(innerObj) + '&';
                                }
                            }
                        }
                        else if (value !== undefined && value !== null)
                            query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
                    }
                    return query.length ? query.substr(0, query.length - 1) : query;
                };
                return Ajax;
            }(http_1.Http));
            Ajax = __decorate([
                core_1.Injectable(),
                __metadata("design:paramtypes", [http_1.XHRBackend, typeof (_a = typeof ng2_layer_1.NgLayer !== "undefined" && ng2_layer_1.NgLayer) === "function" && _a || Object, typeof (_b = typeof Service_1.Notify !== "undefined" && Service_1.Notify) === "function" && _b || Object])
            ], Ajax);
            exports_1("Ajax", Ajax);
            ;
            AppModule = (function () {
                function AppModule() {
                }
                return AppModule;
            }());
            AppModule = __decorate([
                core_1.NgModule({
                    imports: [platform_browser_1.BrowserModule, http_1.HttpModule, forms_1.FormsModule, Directives_1.DirectivesM, AppRoute_1.appRoutes],
                    declarations: [
                        AppComp_1.AppComp,
                        LoginComp_1.LoginComp,
                        MenuComp_1.MenuComp,
                        ContentComp_1.ContentComp,
                        IndexSettingComp_1.IndexSettingComp,
                        DataComp_1.DataComp,
                        OrderComp_1.OrderComp,
                        UserComp_1.UserComp,
                        SettingComp_1.SettingComp,
                        PayComp_1.PayComp,
                        BindWxComp_1.BindWxComp,
                        BoxComp_1.BoxComp,
                        BoxSettingIndexComp_1.BoxSettingIndexComp, BoxAccountComp_1.BoxAccountComp, BoxAddressComp_1.BoxAddressComp, BoxBaseComp_1.BoxBaseComp, BoxNoticeComp_1.BoxNoticeComp, BoxShipComp_1.BoxShipComp, BoxTimeComp_1.BoxTimeComp,
                        BoxCategoryComp_1.BoxCategoryComp, BoxProductComp_1.BoxProductComp, BoxProductIndexComp_1.BoxProductIndexComp
                    ],
                    bootstrap: [AppComp_1.AppComp],
                    providers: [ng2_layer_1.NgLayer, http_1.XHRBackend, [{ provide: http_1.Http, useClass: Ajax }], Service_1.Notify]
                }),
                __metadata("design:paramtypes", [])
            ], AppModule);
            platform_browser_dynamic_1.platformBrowserDynamic().bootstrapModule(AppModule);
        }
    };
});
